<template>
  <div class="container" ref="mainCon">
    <top-Title :titleText="`违法记载`"></top-Title>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6" v-if="isCzUser()">
            <el-form-item label="施工方名称" class="row-padding-bottom">
              <el-input
                type="text"
                v-model="filterField.keyWords"
                clearable
                placeholder="请输入施工方名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6" v-if="isCzUser()">
            <el-form-item label="主体名称" class="row-padding-bottom">
              <el-input
                v-model="filterField.companyName"
                clearable
                placeholder="请输入单位名称或个人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced && isCzUser()">
            <el-col :lg="8" :xl="6">
              <el-form-item label="事项程度" class="row-padding-bottom">
                <el-select
                  v-model="filterField.disputeRank"
                  clearable
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in rankOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="事项类别" class="row-padding-bottom">
                <el-select
                  class="selectWidth"
                  v-model="filterField.preciseTypeId"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in accidentTypeList"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <template v-if="!isCzUser()">
            <el-col :lg="8" :xl="6">
              <el-form-item label="事项程度" class="row-padding-bottom">
                <el-select
                  v-model="filterField.disputeRank"
                  clearable
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in rankOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="事项类别" class="row-padding-bottom">
                <el-select
                  class="selectWidth"
                  v-model="filterField.preciseTypeId"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in accidentTypeList"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item>
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
                v-if="isCzUser()"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_QY_RIGHTS_DISPUTE"
                v-if="!isCzUser()"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          v-loading="loading"
          stripe
          style="border: 1px solid #dfe6ec"
          @sort-change="sortChange"
        >
          <el-table-column label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="pbName"
            label="施工方名称"
            width="230"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pbName"
                :columnName="'pbName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="pbUscc"
            label="施工方统一社会信用代码"
            align="center"
            :formatter="formatTd"
            min-width="200"
          >
            <template slot-scope="scope">
              <p v-if="isCzUser()">
                {{ scope.row.pbUscc | deseHandler(4, 4, '*') || '' }}
              </p>
              <p v-else>{{ scope.row.pbUscc || '' }}</p>
            </template>
          </el-table-column>
          <el-table-column label="责任主体名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.companyName"
                :columnName="'companyName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="uscc"
            label="责任主体证件号码"
            align="center"
            :formatter="formatTd"
            min-width="200"
          >
            <template slot-scope="scope">
              <p v-if="isCzUser()">
                {{ scope.row.uscc | deseHandler(4, 4, '*') || '' }}
              </p>
              <p v-else>{{ scope.row.uscc || '' }}</p>
            </template>
          </el-table-column>
          <el-table-column label="事项类别" width="200">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.preciseTypeName"
                :columnName="'preciseTypeName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="disputeDate"
            sortable="custom"
            label="事项时间"
            align="center"
            :formatter="formatTd"
            min-width="140"
          ></el-table-column>
          <el-table-column label="事项发生地区" width="200">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.address"
                :columnName="'address'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="disputeRankDesc"
            label="事项程度"
            align="center"
            :formatter="formatTd"
            min-width="90"
          ></el-table-column>
          <!-- <el-table-column prop="creatorName" label="添加人" align="center" :formatter="formatTd" min-width="120"></el-table-column>
        <el-table-column prop="createTime" label="添加时间" align="center" :formatter="formatTd" min-width="110">
             <template slot-scope="scope">
            <span>{{common.GMTFormat(scope.row.createTime,true)}}</span>
          </template>
        </el-table-column> -->
          <el-table-column
            prop="balance"
            sortable="custom"
            label="涉及金额（元）"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column
            prop="peopleTotal"
            sortable="custom"
            label="涉及人数（人）"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column
            prop="result"
            label="处理结果"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.result"
                :columnName="'result'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left" fixed="right" width="80">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-hasBtn="[
                  'illegalRecordJSF:detail',
                  'superviseEventSGF:detail',
                  'illegalRecord:detail',
                ]"
                @click="toDetail(scope.row)"
                v-if="!isCzUser()"
                >查看</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>

        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
import scrollTable from '@/mixin/scrollTable.js'
import emptyTable from '@/components/publicCom/emptyTable'
import Pagination from '@/components/publicCom/pagination'
import topTitle from '@/components/publicCom/topTitle'
export default {
  name: 'illagl',
  mixins: [scrollTable],
  components: {
    topTitle,
    emptyTable,
    Pagination,
  },
  data() {
    return {
      userType: '', //账号角色
      advanced: false,
      rankOptions: [],
      accidentTypeList: [], //事项下拉
      filterField: {
        disputeRank: '',
        preciseTypeId: '', //事项类别
        companyName: '',
        keyWords: '',
      },
      requestUrl: 'api-r/rightsdispute/expand/listbycompanybypage',
      tableList: [],
      loading: true,
      isShow: false,
      advanced: false,
    }
  },
  created() {
    this.userType = this.$store.state.userType
    if (
      this.userType === 'PROJECT_ADMINISTRATOR' ||
      this.userType === 'LABOR_ADMINISTRATOR' ||
      this.userType === 'PROJECT_OWNER'
    ) {
      Object.assign(this.filterField, {
        projectId: this.$store.state.projectId,
      })
    } else if (this.userType === 'COMPANY') {
      Object.assign(this.filterField, {
        sysAppCode: localStorage.getItem('judgeRoleCode'),
      })
    }
    this.getRank()
  },
  async mounted() {
    await this.getSelecData('DISPUTE_TYPE')
    const { preciseTypeId } = this.$route.query || ''
    this.filterField.preciseTypeId = preciseTypeId
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    /**
     * @description: 事项类别下拉
     * @param {*} type
     * @return {*}
     */
    getSelecData(type) {
      return this.axios({
        method: 'post',
        url: 'api-bs/base/dicitem/findbytype',
        data: { type },
      })
        .then((res) => {
          if (type == 'DISPUTE_TYPE') {
            this.accidentTypeList = res.data.result
          }
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData()
      })
    },
    getRank() {
      this.axios({
        method: 'post',
        url: 'api-r/rightsdispute/expand/getRank',
        data: {},
      })
        .then((response) => {
          this.rankOptions = response.data.result
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取事项程度数据失败',
            type: 'error',
          })
        })
    },
    toDetail(row) {
      this.$router.push({
        path: '/home/illegal/recordDetail',
        name: 'illegalRecordDetail',
        query: {
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/illegal/illegalRecord',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>
<style lang="less" scoped>
.alert {
  width: 100%;
}
.mainCon {
  top: 198px;
}
@import '../../../static/css/filterArea.less';
</style>
